#include('header.html')
<script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/echarts/4.8.0/echarts.min.js"></script>
<script type="text/javascript" src="/static/style/admin/js/table.js"></script>
<script type="text/javascript">
    changeTab('打分阶段');
    
    $(function () {
        $('select[name="type"]').change(function (e) {
            $('#stage-form').submit();
        });

        $('.pop-close, .pop-dialog').click(function (e) {
            $('.pop-dialog').fadeOut();
        });
        // 阻止冒泡事件
        $('.pop-body').click(function (e) {
            e.stopPropagation();
        });
    });

    function gotoPage(e, page) {
        var type = $('select[name="type"]').val();
        var pages = ${pages.totalPages};
        var status = $(e).parent().attr("class");
        if (page > 0 && page <= pages && page !== ${pages.number + 1} &&
            status !== "active") {
            location.href = '/admin/stage?pageNo=' + page + "&type=" + type;
        }
    }

    function c_delete(id, k_name) {
        var flag = confirm("确定要删除<" + k_name + ">吗？");
        if (flag) {
            $.post('/stage/delete/' + id, function (data) {
                if (data.success) {
                    alert("SUCCESS: 删除成功！");
                    location.reload();
                } else {
                    alert("ERROR: " + data.msg);
                    location.reload();
                }
            });
        }
    }

    /**
     * 重新统计阶段记录
     * @param id 阶段id
     */
    function refresh_(id) {
        $.post('/stageCount/recount', {
            id: id
        });
    }

    /**
     * 重新开始这个阶段的打分
     * @param stageId 打分阶段Id
     */
    function restart(stageId) {
        $.post('/mark/restart', {
            id: stageId
        }, function (data) {
            console.log(data);
            if (data.success) {
                location.href = "/admin/mark";
            } else {
                alert("ERROR: " + data.msg);
            }
        });
    }
</script>

<div class="pop-dialog" style="display: none;">
    <div class="pop-body">
        <span class="pop-close">&bigotimes;</span>
        <span class="label label-info numbers">总人数：<b>0</b></span>
        <div id="stage" style="height: 85%; width: 100%;"></div>
        <div class="text-center pop-btns"></div>
    </div>
</div>

<div class="plan-xcontent">
    <div>
        <div class="col-lg-12 col-xs-12">
            <a class="text-black" href="/admin/stage">
                <h4><span class="fa fa-hand-o-right"></span> 打分阶段</h4>
            </a>
            <div style="padding: 15px 5px 0;" class="pull-right">
                <div id="loading" class="pull-left hidden" style="padding: 4px 10px;">
                    <img class="" width="20" src="/static/images/loading.jpg" alt="加载中">
                </div>
            </div>
        </div>
        <div>
            <div class="col-lg-12 col-xs-12">
                <table class="table table-striped">
                    <thead class="bg-color-x">
                    <tr>
                        <td>排名</td>
                        <td>阶段名</td>
                        <!--<td>阶段类型</td>-->
                        <td>开始时间</td>
                        <td>结束时间</td>
                        <td>参与人数</td>
                        <td style="width: 260px;">操作</td>
                    </tr>
                    </thead>
                    <tbody>
                        #for(Stage s : pages.content)
                        <tr>
                            <td>${for.index}</td>
                            <td>${s.name}</td>
                            <!--<td><span class="stage-type-${s.type}"></span></td>-->
                            <td>${s.beginTime.format("yyyy-MM-dd HH:mm")}</td>
                            <td>${s.id == stageId ? '<span class="label label-success">进行中</span>' : s.endTime.format("yyyy-MM-dd HH:mm") ?! '未结束'}</td>
                            <td><span class="label label-info">${s.userSum ?! '10'}</span></td>
                            <td>
                                <button onclick="showStageStarTable('${s.id}');"
                                        class="btn btn-xs btn-info">查看详情</button>
                                #if(admin.grade > 1)
                                #if(s.id != stageId)
                                <button onclick="refresh_('${s.id}')"
                                        class="btn btn-xs btn-primary">刷新记录</button>
                                #end
                                #if(stageId <= 0)
                                <button onclick="restart('${s.id}')" class="btn btn-xs btn-success">重新开始</button>
                                #end
                                <button onclick="c_delete('${s.id}', '${s.name}');"
                                        class="btn btn-xs btn-danger">删除</button>
                                #end
                            </td>
                        </tr>
                        #else
                        <tr>
                            <td align="center" colspan="7">暂无数据</td>
                        </tr>
                        #end
                    </tbody>
                </table>
                <!-- 分页按钮 -->
                #if(pages.totalPages > 1)
                    <div class="col-lg-12 col-xs-12 text-center">
                        <ul style="margin: 0;" class="pagination pagination-sm">
                            <!--<li onclick="gotoPage(this, 1)"><a href="javascript:">首页</a></li>
                            #for(int i : range(1, pages.totalPages))
                            <li class="${i == pages.number + 1 ? 'active':''}"
                                onclick="gotoPage(this, ${i})"><a href="javascript:">${i}</a></li>
                            #end
                            <li onclick="gotoPage(this, ${pages.totalPages})"><a href="javascript:">尾页</a></li>-->
                        </ul>
                        <span style="padding-top: 15px; font-size: 12px;" class="pull-right">
                            共${pages.totalPages}页，${pages.totalElements}条数据
                        </span>
                    </div>
                #end
            </div>
        </div>
    </div>
</div>

#include('footer.html')